<template>
  <div class="nav-menu">
    <el-menu
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#0c2135"
      text-color="#b7bdc3"
      active-text-color="#0a60bd"
    >
      <template v-for="menu in menus" :key="menu.id">
        <!-- 一级折叠菜单 -->
        <el-sub-menu
          :index="menu.id + ''"
          v-if="menu.children && menu.children.length > 0"
          :class="{ subMenuTwo: menu.type > 1 }"
        >
          <template #title>
            <el-icon v-if="menu.type == 1 && menu.icon">
              <component :is="iconComponent[menu.icon]"></component>
            </el-icon>
            <span>{{ menu.name }}</span>
          </template>

          <tree-menu :menus="menu.children"></tree-menu>
        </el-sub-menu>
        <el-menu-item class="oneMenu" v-else :index="menu.id + ' '">
          {{ menu.name }}
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { Monitor, Setting, Goods, ChatLineRound } from '@element-plus/icons-vue'
interface treeMenuProps {
  menus: any
}
const props = withDefaults(defineProps<treeMenuProps>(), {
  menus: () => {
    return {}
  }
})
const iconComponent: any = {
  'el-icon-monitor': Monitor,
  'el-icon-setting': Setting,
  'el-icon-goods': Goods,
  'el-icon-chat-line-round': ChatLineRound
}
const handleOpen = () => {}
const handleClose = () => {}
</script>

<style lang="less" scoped>
.nav-menu {
  .el-menu {
    border-right: none;
  }
  .el-submenu {
    background-color: #001529 !important;
    // 二级菜单 ( 默认背景 )
    .el-menu-item {
      padding-left: 50px !important;
      background-color: #0c2135 !important;
    }
  }

  ::v-deep .el-submenu__title {
    background-color: #001529 !important;
  }
  .el-menu-item:hover {
    color: #fff !important; // 菜单
  }
  .el-menu-item.is-active {
    color: #fff !important;
    background-color: #0a60bd !important;
  }
}
.el-menu-vertical:not(.el-menu--collapse) {
  width: 100%;
  height: calc(100% - 48px);
}
</style>
